package bocchi.card;

import bocchi.base.BaseCustomCard;
import bocchi.BocchiCore;
import com.megacrit.cardcrawl.actions.common.AttackDamageRandomEnemyAction;
import com.megacrit.cardcrawl.actions.utility.UseCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import java.util.List;
import java.util.stream.Collectors;

public class Headbanging extends BaseCustomCard {
    private static final String RAW_ID = Headbanging.class.getSimpleName();
    public static final String GAME_ID = BocchiCore.getGameID(RAW_ID);

    public Headbanging() {
        super(RAW_ID);
        exhaust = true;
    }

    @Override
    public void use(AbstractPlayer player, AbstractMonster monster) {
        for (int i = 0; i < this.magicNumber; ++i) {
            this.addToBot(new AttackDamageRandomEnemyAction(this));
        }

        List<AbstractCard> attackCards = player.hand.group.stream()
                .filter(card -> card.type == CardType.ATTACK)
                .collect(Collectors.toList());

        if (!attackCards.isEmpty()) {
            AbstractCard card = attackCards.get(AbstractDungeon.cardRandomRng.random(attackCards.size() - 1));
            this.addToBot(new UseCardAction(card));
        }
    }
}
